package com.yigerende.controller;

import com.yigerende.feign.UserFeign;
import com.yigerende.pojo.TUser;
import com.yigerende.pojo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserFeign userFeign;

    //进入user
    @RequestMapping("jr")
    public String user(){
        return "user_manage";
    }

    //user异步请求
    @GetMapping("/findAll")
    @ResponseBody
    public UserVo findAll(@RequestParam("page") int page,@RequestParam("limit") int limit){
        UserVo userVo = userFeign.findAll(page,limit);
        return userFeign.findAll(page,limit);
    }

    //进入增加页面
    @GetMapping("/prepareSave")
    public String prepareSave(){
        return "user_add";
    }

    //增加
    @PostMapping("/save")
    public String save(TUser tUser){
        userFeign.save(tUser);
        return "redirect:/user/jr";
    }


    //删除
    @GetMapping("/deleteById/{id}")
    public String deleteById(@PathVariable("id") Integer id){
        userFeign.deleteById(id);
        return "redirect:/user/jr";
    }
}
